//
//  TwoCell.m
//  CellFactoryModel
//
//  Created by 向祖华 on 16/4/22.
//  Copyright © 2016年 向祖华. All rights reserved.
//

#import "TwoCell.h"

static NSInteger cellHeight = 0;
@implementation TwoCell

-(RootTableViewCell*)initWithDataModel:(DataModel*)model{
    self.backgroundColor = [UIColor cyanColor];
    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 200, 30)];
    self.lable.text = model.title;
    [self addSubview:self.lable];
    UIImage *image = [UIImage imageNamed:model.imageOneName];
    //两张图片可确定图片的显示尺寸
    CGSize size = CGSizeMake(kScreenW/2 , ((kScreenW/2)/image.size.width)*image.size.height);
    //判断是否有文字，确定图片的位置
    CGPoint point;
    
    if ([model.title length]==0) {
        self.lable.hidden = YES;
        point = CGPointMake(0, 10);
    } else {
        self.lable.hidden = NO;
        point = CGPointMake(0, 40);
    }

    self.imageVOne = [[UIImageView alloc] initWithFrame:CGRectMake(point.x, point.y, size.width, size.height)];
    self.imageVOne.image = image;
    [self addSubview:self.imageVOne];
    self.imageVTwo = [[UIImageView alloc] initWithFrame:CGRectMake(point.x+kScreenW/2, point.y, size.width, size.height)];
    self.imageVTwo.image = [UIImage imageNamed:model.imageTwoName];
    [self addSubview:self.imageVTwo];
    
    cellHeight = CGRectGetMaxY(self.imageVTwo.frame);
    return self;
}

-(CGFloat)cellHeight{
    return cellHeight;
}

@end
